package cc.io24.knewcafe.boss.controller;

import cc.io24.knewcafe.boss.service.LoginService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/login")
public class UserLoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     *
     * @param requestJson
     * @return
     */
    @PostMapping(value="/auth",produces="application/json")
    public JSONObject authLogin(@RequestBody JSONObject jsonObject) {
        //CommonUtil.hasAllRequired(requestJson, "username,password");
        String username = jsonObject.getString("username");
        String password = jsonObject.getString("password");
        return loginService.authLogin(username,password);
    }

    /**
     * 查询当前登录用户的信息
     *
     * @return
     */
    @PostMapping(value="/getInfo",produces="application/json")
    public JSONObject getInfo() {
        return loginService.getInfo();
    }

    /**
     * 登出
     *
     * @return
     */
    @PostMapping(value="/logout",produces="application/json")
    public JSONObject logout() {
        return loginService.logout();
    }

}
